from sklearn import metrics
import matplotlib.pyplot as plt
import pandas as pd



def plotROC(y_true,y_pred,label_name,filepath,rootpath='./'):
    # 设置曲线的颜色
    color=['r','k','RoyalBlue','yellow','lime']

    # 设置图片大小
    plt.figure(figsize=(8, 6))

    for i in [0,1,2,3,4]:
        lab=label_name[i]+'=%0.4f'
        fpr,tpr,thresholds=metrics.roc_curve(y_true[i], y_pred[i])
        roc_auc=metrics.auc(fpr, tpr)
        plt.plot(fpr, tpr, label=lab % roc_auc,linewidth = 2.0, linestyle = '-',color=color[i])

    for i in [5,6,7,8,9]:
        lab=label_name[i]+'=%0.4f'
        fpr,tpr,thresholds=metrics.roc_curve(y_true[i], y_pred[i])
        roc_auc=metrics.auc(fpr, tpr)
        plt.plot(fpr, tpr, label=lab % roc_auc,linewidth = 2.0, linestyle = ':',color=color[i-5])



    Font1 = {'size': 13, 'family': 'Times New Roman'}
    #设置图例表示字体，位置等
    plt.legend(loc='lower right', prop=Font1)
    plt.plot([0, 1], [0, 1], 'r--')

    plt.xlim([0, 1])
    plt.ylim([0, 1])
    #设置横纵轴标识字体
    Font2 = {'size': 18, 'family': 'Times New Roman'}
    plt.ylabel('True Positive Rate', Font2)
    plt.xlabel('False Positive Rate', Font2)

    #设置横纵轴上的刻度大小，颜色，特殊效果等
    plt.tick_params(labelsize=15)

    plt.savefig(rootpath + filepath + '-ROC.png', dpi=None, facecolor='w', edgecolor='w',
                orientation='portrait', format=None, transparent=False, bbox_inches=None,
                pad_inches=0.1)
    # plt.show()
    plt.cla()
    plt.close("all")



# datasets=['pred_GINConvNet_Enzyme_under_n2_1.csv','pred_GINConvNet_Enzyme_under_n10_1.csv',
#           'pred_GINConvNet_Enzyme_under_n20_1.csv','pred_GINConvNet_Enzyme_under_n30_1.csv']
# datasets=['pred_GINConvNet_GPCR_under_n2_1.csv','pred_GINConvNet_GPCR_under_n10_1.csv',
#           'pred_GINConvNet_GPCR_under_n20_1.csv','pred_GINConvNet_GPCR_full_1.csv']
# datasets=['pred_GINConvNet_IonChannel_under_n2_1.csv','pred_GINConvNet_IonChannel_under_n10_1.csv',
#           'pred_GINConvNet_IonChannel_under_n20_1.csv','pred_GINConvNet_IonChannel_full_1.csv']
# datasets=['pred_GINConvNet_NuclearReceptor_under_n2_1.csv','pred_GINConvNet_NuclearReceptor_under_n10_1.csv',
#           'pred_GINConvNet_NuclearReceptor_full_1.csv']
# label=['double','10 times','20 times','30 times']
# filename='E_negative_test'


file='NuclearReceptor'
n=10
datasets=[]
for i in range(n):
    datasets.append('pred_GINConvNet_'+file+'_under_n10_'+str(i+1)+'.csv')
label=['1st fold','2nd fold','3rd fold','4th fold','5th fold',
       '6th fold','7th fold','8th fold','9th fold','10th fold']
filename=file+'_10fold'
dirpath='./data/result_pred/10fold/'

y_true=[]
y_pred=[]
for dataset in datasets:
    f=pd.read_csv(dirpath+dataset)
    print(dirpath+dataset)
    y_true.append(list(f['y_true']))
    y_pred.append(list(f['y_pred']))
plotROC(y_true,y_pred,label,filepath=filename)
